<style lang="less" scoped>
    .productversion {
        width: 100%;
        height: auto;
        overflow: hidden;
        text-align: center;
        padding: 8px;
        //display: flex;
    }
</style>
<template>
    <div class="productversion">
        <!--<my-card v-if="$route.params.id != 'all'" cardtitle="当前产品：" :showright="false">-->
            <!--<Table :columns="columns" :data="mydata" style="margin-bottom: 10px"></Table>-->
        <!--</my-card>-->
        <card-table
            style="margin-top: 10px"
            cardtitle="版本列表"
            addbuttext="添加版本"
            :columns="columns"
            :selectList="selectList"
            :defaultSelete="defaultSelete"
            :searchForm="searchForm"
            :formItem="formItem"
            :addbtn="false"
            @add="add"
            @refresh="refresh"
            @on-current-change="onCurrentChange"
            :data="data">
        </card-table>
    </div>
</template>
<script>
    import CardTable from '../components/cardTable.vue'
    import MyCard from '../components/myCard.vue'
    import workorderdata from './workorderdata.js'
    export default {
        name: 'productversion',
        props: ['id'],
        data () {
            return {
                nid: null,
                columns: [
                    {
                        title: '产品编号',
                        key: 'nub',
                        width: 130
                    },
                    {
                        title: '客户产品编号',
                        key: 'cnumber',
                        width: 130
                    },
                    {
                        title: '产品名称',
                        key: 'name'
                    },
                    {
                        title: '产品规格',
                        key: 'norm'
                    },
                    {
                        title: '产品颜色',
                        key: 'color'
                    },
                    {
                        title: '机种',
                        key: 'machine',
                        render: (h, params) => {
                            let data = ''
                            for (let i in params.row.machine) {
                                data += params.row.machine[i] + ','
                            }
                            return h('span', data.substring(0, data.length - 1))
                        }
                    },
                    {
                        title: '单位',
                        key: 'unit',
                        width: 80
                    },
                    {
                        title: '图号',
                        key: 'version',
                        width: 120
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        render: (h, params) => {
                            return h('div', {
                                style: {
                                    display: 'flex',
                                    justifyContent: 'center'
                                }
                            }, [
                                h('Button', {
                                    props: {
                                        type: 'text'
                                    },
                                    on: {
                                        'click': () => {
                                            let test = {
                                                name: '工艺管理',
                                                id: 'technology',
                                                type: true,
                                                url: '/main/technology/'+params.row.id
                                            }
                                            this.util.switchHeadTag(this.$parent, test, this.$store.state.tagdata)
                                        }
                                    }
                                }, '工艺管理'),
                                h('Button', {
                                    props: {
                                        type: 'text'
                                    },
                                    on: {
                                        'click': () => {
                                            console.log('BOM管理')
                                            let test = {
                                                name: 'BOM管理',
                                                id: 'productbom',
                                                type: true,
                                                url: '/main/productbom/'+params.row.id
                                            }
                                            this.util.switchHeadTag(this.$parent, test, this.$store.state.tagdata)
                                        }
                                    }
                                }, 'BOM管理')
                            ]);
                        }
                    }
                ],  //  表格列,
                mydata: [],
                data: [],  //  表格数据
                selectList: [
                    {
                        label: '产品编号',
                        value: 'nub'
                    }
                ],  //  搜索下拉列表
                defaultSelete: 'nub',  //  搜索下拉列表默认值
                searchForm: {
                    'nub': ''
                },  //  表单初始值
                formItem: [
                    {
                        label: '产品编号',
                        key: 'nub',
                        placeholder: '输入产品编号'
                    }
                ],  //  搜索表单item
                current: null
            }
        },
        methods: {
            add () {
                console.log('customer触发了添加事件')
            },
            refresh () {
                this.http.getAllProductV(this, {})
            },
            onCurrentChange (current) {
                console.log(current)
                this.current = current
            }
        },
        components: {
            CardTable,
            MyCard
        },
        activated: function () {
            if (this.$route.params.id == 'all') {
                this.http.getAllProductV(this, {})
            } else {
                if (this.nid == null && this.nid != this.$route.params.id) {
                    this.http.getProductVByNub(this, {nub: this.$route.params.id})
                }
            }
        },
        mounted: function () {
            if (this.$route.params.id == 'all') {
                this.http.getAllProductV(this, {})
            } else {
                this.http.getProductVByNub(this, {nub: this.$route.params.id})
            }
        }
    };
</script>
